#!/bin/bash

APP_NAME=storage-service

ZIP_NAME=${APP_NAME}-bin-package.tar.gz
REMOTE_DIR=/home/admin

echo "开始传输文件"
scp target/${ZIP_NAME} root@work-server:${REMOTE_DIR}
echo "文件传输完毕"

echo "登陆远程服务器"
ssh root@work-server << EOF
  cd ${REMOTE_DIR}
  if [ -e ${APP_NAME} ]; then
    echo "关闭服务"
    cd ${APP_NAME}
    ./deploy.sh stop
    cd ..
    rm -rf ${APP_NAME}
    echo "服务关闭完成"
  fi
  tar -zxvf ${ZIP_NAME}
  cd ${APP_NAME}
  ./deploy.sh start
EOF
echo "服务部署完毕"